﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<JobDescOnline.Presentation.Models.CompetencyModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Edit Competency - Review JobDesc!
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="SideMenu" runat="server">
    <% Html.RenderPartial("MasterDataMenu"); %>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        function InsertLevelCompetency() {
            $.ajax({
                url: "/LevelCompetency/Create",
                type: "POST",
                data: { CompetencyID: $("[name=ID]").val(), Level: $("[name=Level]").val(), Definition: $("[name=Definition]").val() },
                success: function (msg) {
                    if (msg) {
                        $("#LevelBody").html(msg);
                        $("[name=Level]").val("");
                        $("[name=Definition]").val("");
                    }
                }
            });

            return false;
        }

        function SaveLevelCompetency(id) {
            $.ajax({
                url: "/LevelCompetency/Edit/" + id,
                type: "POST",
                data: { CompetencyID: $("[name=ID]").val(), Level: $("[name=Level" + id + "]").val(), Definition: $("[name=Definition" + id + "]").val() },
                success: function (msg) {
                    if (msg) {
                        $("#LevelBody").html(msg);
                    }
                }
            });

            return false;
        }

        function DeleteLevelCompetency(id) {
            $.ajax({
                url: "/LevelCompetency/Delete/" + id,
                success: function (msg) {
                    if (msg) {
                        $("#LevelBody").html(msg);
                    }
                }
            });

            return false;
        }
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Kompetensi - Ubah Data!</h2>

    <% Html.EnableClientValidation(); %>
    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>
        <fieldset>
            <legend>Informasi Umum</legend>
            <%: Html.Hidden("ID", Model.Competency.ID) %>

            <table>
                <tr>
                    <td><%: Html.LabelFor(model => model.Competency.CreatedBy) %></td>
                    <td>
                        <%: Html.TextBoxFor(model => model.Competency.CreatedBy, new { @readonly = "readonly" })%>
                        <%: Html.ValidationMessageFor(model => model.Competency.CreatedBy)%>
                    </td>
                    <td><%: Html.LabelFor(model => model.Competency.CreatedOn)%></td>
                    <td>
                        <%: Html.TextBoxFor(model => model.Competency.CreatedOn, new { @readonly = "readonly" })%>
                        <%: Html.ValidationMessageFor(model => model.Competency.CreatedOn)%>
                    </td>
                </tr>
                <tr>
                    <td><%: Html.LabelFor(model => model.Competency.LastModifiedBy)%></td>
                    <td>
                        <%: Html.TextBoxFor(model => model.Competency.LastModifiedBy, new { @readonly = "readonly" })%>
                        <%: Html.ValidationMessageFor(model => model.Competency.LastModifiedBy)%>
                    </td>
                    <td><%: Html.LabelFor(model => model.Competency.LastModifiedOn)%></td>
                    <td>
                        <%: Html.TextBoxFor(model => model.Competency.LastModifiedOn, new { @readonly = "readonly" })%>
                        <%: Html.ValidationMessageFor(model => model.Competency.LastModifiedOn)%>
                    </td>
                </tr>
            </table>
        </fieldset>
        <fieldset>
            <legend>Data Kompetensi</legend>
            
            <div class="editor-label">
                <%: Html.LabelFor(model => model.Competency.Rowstatus)%>
            </div>
            <div class="editor-field">
                <%: Html.DropDownList("Competency.Rowstatus", (IEnumerable<SelectListItem>)HttpContext.Current.Application["Active"], "--Select One--")%>
                <%: Html.ValidationMessageFor(model => model.Competency.Rowstatus)%>
            </div>
            
            <div class="editor-label">
                <%: Html.LabelFor(model => model.Competency.Description)%>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.Competency.Description, new { style = "width: 300px" })%>
                <%: Html.ValidationMessageFor(model => model.Competency.Description)%>
            </div>

            <div class="editor-label">
                <%: Html.LabelFor(model => model.Competency.Definition)%>
            </div>
            <div class="editor-field">
                <%: Html.TextAreaFor(model => model.Competency.Definition, new { style = "width: 900px" })%>
                <%: Html.ValidationMessageFor(model => model.Competency.Definition)%>
            </div>
        </fieldset>

        <fieldset id="LevelKompetensi">
            <legend>Level Kompetensi: </legend>
            <table class="withborder">
                <thead>
                    <tr>
                        <th style="width: 80px;">Level</th>
                        <th>Definisi</th>
                        <th style="width: 55px"></th>
                    </tr>
                </thead>
                <tbody id="LevelBody">
                <% foreach (var res in Model.LevelCompetencies) { %>
                    <tr valign="top">
                        <td>
                            <%= Html.Hidden("CompetencyID" + res.ID.ToString(), res.CompetencyID)%>
                            <%= Html.TextBox("Level" + res.ID.ToString(), res.Level)%>
                        </td>
                        <td><%= Html.TextArea("Definition" + res.ID.ToString(), res.Definition)%></td>
                        <td style="text-align: center">
                            <input type="button" onclick="return SaveLevelCompetency(<%= res.ID.ToString() %>);" value="Simpan" />
                            <input type="button" onclick="return DeleteLevelCompetency(<%= res.ID.ToString() %>);" value="Hapus" />
                        </td>
                    </tr>
                <% } %>
                </tbody>
                <tfoot>
                    <tr valign="top">
                        <td><%= Html.TextBox("Level", "", new { onkeydown = "return ValidateNumber(event);" })%></td>
                        <td><%= Html.TextArea("Definition", "") %></td>
                        <td><input type="button" value="Tambah" onclick="return InsertLevelCompetency();" /></td>
                    </tr>
                </tfoot>
            </table>
        </fieldset>

        <p><input type="submit" value="Simpan" /></p>
    <% } %>

    <div><%: Html.ActionLink("Kembali", "Index") %></div>
</asp:Content>

